# -*- coding: utf-8 -*-
"""
Created on Wed Sep 18 22:31:35 2024

@author: Administrator
"""


from tkinter import *

from dataclasses import dataclass

@dataclass
class House:
    w:int 
    h:int 
    roof_color:str
    wall_color:str()
    
#house = House(200,200,"red","gray")

#print (house)


def draw_house_at(house,x,y,canvas):
  
    w=house.w
    h=house.h
    roof_color=house.roof_color
    wall_color=house.wall_color
    rtop_x=x+w/2 #house top x
    wtop_y=y+h/2 #house top y
    bottom_x=x+w #house bottom x
    bottom_y=y+h #house bottom y
    canvas.create_polygon(rtop_x,y, #顶点
                          x,wtop_y, #左下
                          x+w,wtop_y, #右上
                          outline=roof_color,
                          fill = roof_color
                          )
    canvas.create_rectangle(x,wtop_y,
                            bottom_x,bottom_y,
                            outline=wall_color,
                            fill=wall_color
                            
                            )
    
tk = Tk()

canvas = Canvas(tk,width=800,height=400,bd=0)
canvas.pack()

house_array=[
    House(w=50, h=100, roof_color="green", wall_color="yellow"),
     House(w= 80, h=100, roof_color="red", wall_color="green"),
      House(w=60, h=60, roof_color="red", wall_color="green"),
       House(w=30, h=100, roof_color="red", wall_color="green")
    ]

x=0
y=100
PAD = 50 
for house in house_array:
    draw_house_at(house,x,y, canvas)
    x+=house.w+PAD
    

tk.mainloop()

  
    
    